window.onload = function () {
  var regtel = /^1[3|4|5|7|8]\d{9}$/; // 手机号码正则
  var regqq = /^[1-9]\d{4,}$/; // qq正则
  var regnc = /^[\u4e00-\u9fa5]{2,8}$/; // 昵称正则
  var regyzm = /^\d{6}$/; //验证码正则
  var regmm = /^[a-zA-Z0-9_-]{6,16}$/; //登陆密码
  var tel = document.querySelector("#tel"); // 手机
  var qq = document.querySelector("#qq"); // qq
  var nc = document.querySelector("#nc"); // 昵称
  var yzm = document.querySelector("#msg"); // 验证码
  var mm = document.querySelector("#pwd"); //登陆密码
  var surepwd = document.querySelector("#surepwd");
  Regtoto(tel, regtel); // 手机号码 调用正则
  Regtoto(qq, regqq); // qq 调用正则
  Regtoto(nc, regnc); // 昵称调用
  Regtoto(yzm, regyzm); // 验证码调用正则
  Regtoto(mm, regmm); // 登陆密码 调用正则
  function Regtoto(ele, reg) {
    console.log(ele);
    ele.onblur = function () {
      if (reg.test(this.value)) {
        this.nextElementSibling.className = "success";
        this.nextElementSibling.innerHTML =
          '<i class="success_icon"></i> 恭喜您输入正确';
      } else {
        this.nextElementSibling.className = "error";
        this.nextElementSibling.innerHTML =
          '<i class="error_icon"></i> 格式不正确，请从新输入 ';
      }
    };
    surepwd.onblur = function () {
      if (this.value === 0) {
        this.nextElementSibling.className = "error";
        this.nextElementSibling.innerHTML =
          '<i class="error_icon"></i> 请输入密码';
        return;
      }
      if (this.value === mm.value) {
        this.nextElementSibling.className = "success";
        this.nextElementSibling.innerHTML =
          '<i class="success_icon"></i> 恭喜您输入正确';
      } else {
        this.nextElementSibling.className = "error";
        this.nextElementSibling.innerHTML =
          '<i class="error_icon"></i> 两次输入密码不一致 ';
      }
    };
  }
};
